class Solution {
    public int longestOnes(int[] nums, int k) {
        int left=0,right=0,ret=0;
        int n=nums.length;
        int zero=0;
        while(right<n){
            if(nums[right]==0) 
                zero++;
            while(zero>k){
                if(nums[left]==0) zero--;
                left++;
            }
            ret=Math.max(ret,right-left+1);
            right++;
        }
        return ret;
    }
}